<template>
  <div class="brandListTool">
    <h3 class="toolTit">拼团专区</h3>
    <div class="toolBox">
      <div class="itemBox">
        <label>标题</label>
        <el-input v-model="activeComponent.componentContent.title" placeholder="请输入内容"></el-input>
      </div>
    </div>
    <div v-if="typeId=='1'">
      <product-source-multiple :productData.sync='activeComponent.componentContent.productData' :type="1"></product-source-multiple>
    </div>
    <div class="porListBox" v-else>
      <div class="addProduct">
        <div v-if="!activeComponent.componentContent.activityName" class="addProBtn addImgBtn" @click="selectActivity"><span class="iconfont">&#xe685;</span>选择活动</div>
        <div v-else class="categoryName">
          <span>{{activeComponent.componentContent.activityName}}</span>
          <div class="operation">
            <span class="iconfont" @click="replaceActivity">&#xe66c;</span>
            <span class="iconfont" @click="deleteActivity">&#xe633;</span>
          </div>
        </div>
      </div>
    </div>
    <el-dialog title="选择类别" :visible.sync="showSkillActivity" width="900px">
      <el-table :data='skillActivity' style="width: 100%" @row-click="rowClick" highlight-current-row>
        <el-table-column label width="35">
          <template slot-scope="scope">
            <el-radio :label="scope.row.shopGroupWorkId" v-model="radioId"/>
          </template>
        </el-table-column>
        <el-table-column
          prop="groupName"
          label="标题">
        </el-table-column>
        <el-table-column
          :formatter="getDate"
          width="400"
          label="活动时间">
        </el-table-column>
        <el-table-column
          prop="state"
          label="状态"
          :formatter='getState'>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelSkill">取 消</el-button>
        <el-button type="primary" @click="confirmActivity">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 下面注释部分为逍逍, 看下后面是否用到 -->
    <!-- <div class="toolBox">
      <div class="itemBox">
        <label>标题</label>
        <el-input v-model="activeComponent.componentContent.title" placeholder="请输入内容"></el-input>
      </div>
      <tool-select :linkValue.sync='activeComponent.componentContent.textAlign' title="文字对齐方式" :options="alignList"></tool-select>
      <div class="single-img"></div>
      <div class="textTit">商品来源</div>
      <div class="porListBox">
        <div class="addProduct">
          <div v-if="!activeComponent.componentContent.categoryName" class="addProBtn addImgBtn" @click="addProductCls"><span class="iconfont">&#xe685;</span> 添加类别</div>
          <div v-else class="categoryName">
            <span>{{activeComponent.componentContent.categoryName}}</span>
            <div class="operation">
              <span class="iconfont" @click="replaceCategory">&#xe66c;</span>
              <span class="iconfont" @click="deleteCategory">&#xe633;</span>
            </div>
          </div>
        </div>
      </div>
      <div v-if="terminal == 4">
      </div>
      <div v-else>
        <div class="styleSelectLine">
          <div class="blockTit">
            <span>排列样式</span>
            <span>{{activeComponent.componentContent.arrangeType}}</span>
          </div>
          <div class="selectCompose">
            <div class="composeList">
              <span class="item iconfont" :class="{active: activeComponent.componentContent.arrangeType === item.name}" @click="selectArrange(item)" v-for="(item) of arrangeList" :key="item.id" v-html="item.Icon"></span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="deleteItem">
      <span>点击确定删除此项</span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
    <el-dialog title="选择类别" :visible.sync="dialogCategory" width="600px">
      <el-cascader style="width: 100%"
                   ref="cascader"
                   :options="categoryList"
                   :props="{ checkStrictly: true,label: 'categoryName',value: 'id',children: 'childs' }"
                   clearable></el-cascader>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogCategory = false">取 消</el-button>
        <el-button type="primary" @click="addCategoryData">确 定</el-button>
      </span>
    </el-dialog> -->
  </div>
</template>

<script>
import Cookies from 'js-cookie'
import Draggable from 'vuedraggable'
import api from '@@/components/canvasShow/config/api'
import {toolMixin} from '@@/config/mixin'
import {sendReqMixin} from '@@/components/canvasShow/config/mixin'
import { mapGetters } from 'vuex'
import ToolSelect from '../toolModule/tool-select'
import ToolSingleImg from '../toolModule/tool-single-img'
import ToolSelectLink from '../toolModule/tool-select-link'
import ProductSourceMultiple from '../toolModule/product-source-multiple'
export default {
  mixins: [toolMixin, sendReqMixin],
  name: 'groupTool',
  components: {
    ProductSourceMultiple,
    ToolSelectLink,
    ToolSingleImg,
    ToolSelect,
    Draggable
  },
  data () {
    return {
      radioId: '',
      skillActivity: [],
      selectSkill: {},
      showSkillActivity: false,
      title: '', // 标题内容
      textInfo: '', // 文本
      imgTextData: [
        {
          title: '',
          isShow: true,
          imgData: '',
          describe: '',
          url: ''
        }
      ],
      alignList: [
        {
          id: 1,
          label: '居左',
          value: 'left'
        },
        {
          id: 2,
          label: '居中',
          value: 'center'
        }
      ],
      categoryList: [],
      textAlign: 'left',
      imgCurrent: null,
      dialogVisible: false,
      dialogCategory: false,
      currentCategory: null,
      // categoryName: '', // 类别名称
      productList: [], // 产品列表
      productNum: 2, // 商品展示数量
      labelCurrent: null,
      arrangeList: [
        // {
        //   id: 1,
        //   type: 'L1',
        //   name: '一行一个',
        //   Icon: '&#xe603'
        // },
        {
          id: 2,
          type: 'L2',
          name: '一行两个',
          Icon: '&#xe603'
        },
        {
          id: 3,
          type: 'L4',
          name: '横向滑动',
          Icon: '&#xe603;'
        }
      ]
    }
  },
  computed: {
    ...mapGetters([
      'terminal',
      'typeId'
    ])
  },
  methods: {
    // 时间变换
    getDate(row) {
      return `${row.startTime}至${row.endTime}`
    },
    // 状态变换
    getState(row) {
      const opt = {
        0:"未开始",
        1:"进行中",
        2:"已结束"
      }
      return opt[row.state]
    },
    // 点击选择活动
    selectActivity() {
      this.getActivity()
      this.showSkillActivity = true
      this.radioId = this.activeComponent.componentContent.shopGroupWorkId
    },
    // 获取活动数据
    getActivity() {
      const _ = this
      const params = {
        method: 'GET',
        url: `${api.getGroupWorks}?shopId=${Cookies.get('cereShopId')}`,
      }
      this.sendReq(params, (res) => {
        _.skillActivity = res.data
      })

    },
    // 行点击
    rowClick(row) {
      this.selectSkill = row;
      this.radioId=row.shopGroupWorkId;
    },
    // 确认活动选择
    confirmActivity() {
      this.activeComponent.componentContent.shopGroupWorkId = this.selectSkill.shopGroupWorkId
      this.activeComponent.componentContent.activityName = this.selectSkill.groupName
      this.showSkillActivity = false
    },
    // 取消活动选择
    cancelSkill() {
      this.showSkillActivity = false;
      this.radioId = ''
    },
    // openAddImg (item, index) {
    //   if (this.imgCurrent === index) {
    //     this.imgCurrent = null
    //     return false
    //   }
    //   this.imgCurrent = index
    // },
    // 添加图文
    // addImgText () {
    //   this.activeComponent.componentContent.imgTextData.push({
    //     title: '',
    //     isShow: true,
    //     imgData: '',
    //     url: ''
    //   })
    // },
    // 删除内容
    // deleteItem (item, index) {
    //   this.$confirm('确定删除此项？')
    //     .then(_ => {
    //       this.activeComponent.componentContent.imgTextData.splice(index, 1)
    //     })
    //     .catch(_ => {})
    // },
    // 添加类别
    // addCategoryData () {
    //   let nodesObj = this.$refs['cascader'].getCheckedNodes()
    //   if (nodesObj) {
    //     var categoryId = nodesObj[0].value
    //     var categoryName = nodesObj[0].label
    //     this.activeComponent.componentContent.categoryId = categoryId
    //     this.activeComponent.componentContent.categoryName = categoryName
    //     this.dialogCategory = false
    //     let _this = this
    //     var paramsUrl = `${api.getProducts}?page=1&pageSize=20&classifyId=${this.activeComponent.componentContent.categoryId}`
    //     this.sendReq({
    //       url: paramsUrl,
    //       method: 'GET'
    //     }, (proRes) => {
    //       _this.activeComponent.componentContent.imgTextData = proRes.data.list
    //     })
    //   }
    // },
    // 替换活动
    replaceActivity () {
      this.showSkillActivity = true
      this.getActivity()
    },
    // 删除已选活动
    deleteActivity () {
      this.activeComponent.componentContent.activityName = ''
      this.activeComponent.componentContent.shopGroupWorkId = ''
      this.$forceUpdate()
    },
    // handleAvatarSuccess (res, file) {
    //   this.imageUrl = URL.createObjectURL(file.raw)
    // },
    // 标签手风琴
    // openAddLabel (item, index) {
    //   if (this.labelCurrent === index) {
    //     this.labelCurrent = null
    //     return false
    //   }
    //   this.labelCurrent = index
    // },
    // 添加标签
    // addLabel () {
    //   this.activeComponent.componentContent.labelList.push({
    //     name: '',
    //     url: ''
    //   })
    // },
    // 删除标签
    // deleteLabelItem (item, index) {
    //   this.$confirm('确定删除此项？')
    //     .then(_ => {
    //       this.activeComponent.componentContent.labelList.splice(index, 1)
    //     })
    //     .catch(_ => {})
    // },
    // selectArrange (item) {
    //   this.activeComponent.componentContent.arrangeType = item.name
    // }
  }
}
</script>

<style lang="scss" scoped>
.config-content {
  .item {
    padding: 12px 0;
    border-bottom: 1px #ddd solid;
    &:nth-child(1) {
      border-top: 1px #ddd solid;
    }
  }
  .label-text {
    color: #666;
    span {
      color: hsl(357, 97%, 49%);
      font-size: 20px;
      vertical-align: middle;
      display: inline-block;
      margin-right: 5px;
    }
  }

  .add {
      margin-top: 10px;
      width: 50px;
      height: 50px;
      text-align: center;
      line-height: 50px;
      border:1px #ddd solid;
      box-shadow: 0 0 10px #ddd;
      .el-icon-plus {
        color: blue !important;
      }
      &:hover {
        cursor: pointer;
      }
  }
}


.brandListTool {
  padding: 20px 20px 0px 20px;
  h3 {
    font-size: 18px;
    font-weight: 500;
    height: 35px;
    line-height: 35px;
    color: #333333;
    margin-bottom: 20px;
  }
  .toolBox {
    padding-bottom: 10px;
    .itemBox {
      label {
        font-size: 14px;
        color: #666666;
        height: 40px;
        line-height: 40px;
      }
      margin-bottom: 15px;
    }
    .textTit {
      height: 35px;
      line-height: 35px;
      font-size: 14px;
      color: #333333;
      display: flex;
      justify-content: space-between;
      span {
        font-weight: normal;
        font-size: 14px;
        color: #666666;
      }
    }
    .productTit {
      margin-top: 20px;
      color: #666666;
      height: 35px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      span {
        font-size: 14px;
        color: #666666;
      }
    }
  }
  ::v-deep .el-select {
    width: 100%;
  }
  .addImgBtn {
    border-radius: 4px;
    background: $mainColor;
    text-align: center;
    height: 36px;
    color: #ffffff;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    span {
      font-size: 20px;
      margin-right: 5px;
    }
  }
  .labelLisTit{
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
  }
  .labelListWarp{
    padding-bottom: 20px;
    .imgListBox {
      margin-top: 20px;
      .item {
        border: 1px solid #E8EAEC;
        border-radius: 4px;
        margin-bottom: 10px;
      }
      .listItemBox {
        .addImgTit {
          padding: 10px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          background: #F6F7F9;
          cursor: pointer;
          .titLeft {
            display: flex;
            align-items: center;
            span {
              color: #7D7E80;
            }
            span:nth-child(1) {
              font-size: 28px;
            }
            span:nth-child(2) {
              font-size: 25px;
              margin: 0 6px;
            }
            span:nth-child(3) {
              font-size: 14px;
            }
          }
          .titRight {
            display: flex;
            align-items: center;
            span:nth-child(1) {
              width: 40px;
              text-align: center;
              display: block;
              height: 30px;
              line-height: 30px;
            }
          }
        }
        .addLabelBox{
          padding:0 10px 10px;
          .itemBox{
            margin-bottom: 20px;
            label{
              font-size: 14px;
              color: #666666;
              height: 40px;
              line-height: 40px;
            }
          }
          ::v-deep .module-box{
            margin-bottom: 10px;
          }
        }
        .deleteItem {
          padding: 10px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #F6F7F9;
          cursor: pointer;
          color: $mainColor;
          font-size: 14px;
          span {
            font-size: 16px;
            margin-right: 5px;
          }
        }
      }
    }
  }
}

.styleSelectLine{
  margin-top: 30px;
  .blockTit{
    span{
      margin-right: 16px;
      &:last-child{
        color: $mainColor;
      }
    }
  }
  .composeList{
    display: flex;
    flex-wrap: wrap;
    padding-top: 20px;
    .item{
      width: 50px;
      height: 30px;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 1px solid #E8EAEC;
      color: #999999;
      font-size: 18px;
      text-align: center;
      cursor: pointer;
      &:hover,&.active{
        color: #FF7800;
        border: 1px solid #FF7800;
      }
    }
  }
}

.porListBox {
  padding: 10px;
  background: #F0F3F4;
  .addProduct {
    .categoryName {
      height: 35px;
      display: flex;
      align-items: center;
      background: #e9e9e9;
      border-radius: 4px;
      padding: 0 10px;
      justify-content: space-between;
      span {
        color: #333333;
      }
      span {
        color: #333333;
      }
      .operation {
        display: flex;
        span {
          width: 35px;
          display: block;
          height: 35px;
          line-height: 35px;
          text-align: center;
          cursor: pointer;
        }
      }
    }
    .addProBtn {}
  }
}
</style>
